package com.ruoyi.shop.good.comment.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.common.domain.DtsReply;
import com.ruoyi.mall.common.mapper.DtsCommentMapper;
import com.ruoyi.mall.common.mapper.DtsReplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.common.domain.DtsComment;
import com.ruoyi.shop.good.comment.service.IDtsCommentService;

/**
 * 商品评论Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-21
 */
@Service
public class DtsCommentServiceImpl implements IDtsCommentService
{
    @Autowired
    private DtsCommentMapper dtsCommentMapper;

    @Autowired
    private DtsReplyMapper dtsReplyMapper;

    /**
     * 查询商品评论
     *
     * @param id 商品评论主键
     * @return 商品评论
     */
    @Override
    public DtsComment selectDtsCommentById(Long id)
    {
        return dtsCommentMapper.selectDtsCommentById(id);
    }

    /**
     * 查询商品评论列表
     *
     * @param dtsComment 商品评论
     * @return 商品评论
     */
    @Override
    public List<DtsComment> selectDtsCommentList(DtsComment dtsComment)
    {
        List<DtsComment> dtsCommentList = dtsCommentMapper.selectDtsCommentList(dtsComment);
        int num = 0;
        for (DtsComment dtsComment1 : dtsCommentList) {
            DtsReply dtsReply = new DtsReply();
            dtsReply.setCommentId(dtsComment1.getId());
            List<DtsReply> dtsReplyList = dtsReplyMapper.selectDtsReplyList(dtsReply);
            dtsCommentList.get(num).setDtsReplyList(dtsReplyList);
            dtsCommentList.get(num).setExpanded(false);
            dtsCommentList.get(num).setReplyContent("");
            num++;
        }
        return dtsCommentList;
    }

    /**
     * 新增商品评论
     *
     * @param dtsComment 商品评论
     * @return 结果
     */
    @Override
    public int insertDtsComment(DtsComment dtsComment)
    {
        return dtsCommentMapper.insertDtsComment(dtsComment);
    }

    /**
     * 修改商品评论
     *
     * @param dtsComment 商品评论
     * @return 结果
     */
    @Override
    public int updateDtsComment(DtsComment dtsComment)
    {
        dtsComment.setUpdateTime(DateUtils.getNowDate());
        return dtsCommentMapper.updateDtsComment(dtsComment);
    }

    /**
     * 批量删除商品评论
     *
     * @param ids 需要删除的商品评论主键
     * @return 结果
     */
    @Override
    public int deleteDtsCommentByIds(Long[] ids)
    {
        return dtsCommentMapper.deleteDtsCommentByIds(ids);
    }

    /**
     * 删除商品评论信息
     *
     * @param id 商品评论主键
     * @return 结果
     */
    @Override
    public int deleteDtsCommentById(Long id)
    {
        return dtsCommentMapper.deleteDtsCommentById(id);
    }
}
